package com.nmsl.nurse.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.nurse.domain.MHospitalNursingRecord;
import com.nmsl.nurse.service.IMHospitalNursingRecordService;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.common.core.page.TableDataInfo;

/**
 * 患者住院护理记录Controller
 * 
 * @author mengdi
 * @date 2025-02-19
 */
@RestController
@RequestMapping("/nurse/nurserecord")
public class MHospitalNursingRecordController extends BaseController
{
    @Autowired
    private IMHospitalNursingRecordService hospitalNursingRecordService;

    /**
     * 查询患者住院护理记录列表
     */
    @PreAuthorize("@ss.hasPermi('nurse:nurserecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(MHospitalNursingRecord MHospitalNursingRecord)
    {
        startPage();
        List<MHospitalNursingRecord> list = hospitalNursingRecordService.selectHospitalNursingRecordList(MHospitalNursingRecord);
        return getDataTable(list);
    }

    /**
     * 导出患者住院护理记录列表
     */
    @PreAuthorize("@ss.hasPermi('nurse:nurserecord:export')")
    @Log(title = "患者住院护理记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MHospitalNursingRecord MHospitalNursingRecord)
    {
        List<MHospitalNursingRecord> list = hospitalNursingRecordService.selectHospitalNursingRecordList(MHospitalNursingRecord);
        ExcelUtil<MHospitalNursingRecord> util = new ExcelUtil<MHospitalNursingRecord>(MHospitalNursingRecord.class);
        util.exportExcel(response, list, "患者住院护理记录数据");
    }

    /**
     * 获取患者住院护理记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('nurse:nurserecord:query')")
    @GetMapping(value = "/{nursingRecordId}")
    public AjaxResult getInfo(@PathVariable("nursingRecordId") Long nursingRecordId)
    {
        return success(hospitalNursingRecordService.selectHospitalNursingRecordByNursingRecordId(nursingRecordId));
    }

    /**
     * 新增患者住院护理记录
     */
    @PreAuthorize("@ss.hasPermi('nurse:nurserecord:add')")
    @Log(title = "患者住院护理记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MHospitalNursingRecord MHospitalNursingRecord)
    {
        return toAjax(hospitalNursingRecordService.insertHospitalNursingRecord(MHospitalNursingRecord));
    }

    /**
     * 修改患者住院护理记录
     */
    @PreAuthorize("@ss.hasPermi('nurse:nurserecord:edit')")
    @Log(title = "患者住院护理记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MHospitalNursingRecord MHospitalNursingRecord)
    {
        return toAjax(hospitalNursingRecordService.updateHospitalNursingRecord(MHospitalNursingRecord));
    }

    /**
     * 删除患者住院护理记录
     */
    @PreAuthorize("@ss.hasPermi('nurse:nurserecord:remove')")
    @Log(title = "患者住院护理记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{nursingRecordIds}")
    public AjaxResult remove(@PathVariable Long[] nursingRecordIds)
    {
        return toAjax(hospitalNursingRecordService.deleteHospitalNursingRecordByNursingRecordIds(nursingRecordIds));
    }

//查询护理信息和住院记录表（通过患者id连接）
    @RequestMapping("/list/all")
    public List<MHospitalNursingRecord> listAll(MHospitalNursingRecord MHospitalNursingRecord){
        return hospitalNursingRecordService.selectHospitalNursingRecordListAndMHospitalizationRegistration(MHospitalNursingRecord);
    }
}
